package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.CompanyService;
import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.GetAgentPremisesPageReqDto;
import com.yixun.qfbao.apidto.GetAgentPremisesPageResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.Company;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetAgentPremisesPageReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * 根据省份市区、楼盘查询可报备的楼盘
 *
 * @classname: GetAgentPremisesListHander.java
 * @author: Beau
 * @create: 2020/01/13 15:08
 * @version: 1.0.0
 **/
@Controller("getAgentPremisesListHander")
public class GetAgentPremisesListHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetAgentPremisesListHander.class);
    @Autowired
    private PremisesApiService premisesService;
    @Autowired
    private LoginUtils loginUtils;
    @Autowired
    private CompanyService companyService;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        GetAgentPremisesPageReqVo reqDto1 = (GetAgentPremisesPageReqVo) reqDto;
        GetAgentPremisesPageReqDto dto = reqDto1.getParams();
        BaseResponseDTO<GetAgentPremisesPageResDto> res = new BaseResponseDTO<GetAgentPremisesPageResDto>();
        GetAgentPremisesPageResDto resDto = new GetAgentPremisesPageResDto();
        PartnerInfo pi = loginUtils.getUser(dto.getUserId());
        if (pi == null) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未找到用户信息");
            return res;
        }
        try {
            resDto = premisesService.getAgentPremisesList(dto);
            res.setResData(resDto);
            res.setResult(resDto.getResult());
        } catch (Exception e) {
            logger.error("GetAgentPremisesListHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("楼盘列表获取失败!");
        }
        return res;
    }
}
